//
//  CBJTabBarView.swift
//  Weibo
//
//  Created by 崔健 on 16/5/19.
//  Copyright © 2016年 cbj. All rights reserved.
//

import UIKit

class CBJTabBarView: UITabBar {

    
    override init(frame: CGRect) {
        
        super.init(frame: frame)

        addSubview(plusBtn)
        
    
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        
        super.init(coder: aDecoder)
    }
    
    
    lazy var plusBtn : UIButton = {
    
        let btn = UIButton(type: .Custom)

        btn.setBackgroundImage(UIImage.init(named: "tabbar_compose_button"), forState: .Normal)
        btn.setBackgroundImage(UIImage.init(named: "tabbar_compose_button_highlighted"), forState: .Selected)
       btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: .Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: .Highlighted)
        btn.sizeToFit()

        return btn
    }()
    
    

    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let width = kScreenWidth / 5.0
        let height = self.bounds.height
        
        var index:CGFloat = 0
        for subView in subviews{
        
            if subView.isKindOfClass(NSClassFromString("UITabBarButton")!){
                
                if index == 2 {
                    
                    index += 1
                    
                   let rect = CGRect(x: index * width, y: 0, width: width, height: height)
                    subView.frame = rect
                }else{
                
                
                    let rect = CGRect(x: index * width, y: 0, width: width, height: height)
                    subView.frame = rect
                }
                
                
                index += 1
                
            }
            

        }
        
        
        plusBtn.frame = CGRectMake(2 * width, -20, width, height)
        bringSubviewToFront(plusBtn)
 
    }

}
